﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;
namespace WebSocketApi.Common;

/// <summary>
/// SocketId生成
/// </summary>
public class IdGenerate
{

    /// <summary>
    /// 创建SocketId
    /// </summary>
    /// <returns></returns>
    public static string GenerateNGuid()
    {
        return Guid.NewGuid().ToString("N");
    }

    /// <summary>
    /// 根据请求参数生成标准MD5
    /// </summary>
    /// <param name="request"></param>
    /// <returns></returns>
    public static string GenerateMd5ByRequest(string request)
    {
        using (var md5 = MD5.Create())
        {
            byte[] data = System.Text.Encoding.Default.GetBytes(request);
            byte[] result = md5.ComputeHash(data);
            string response = "";
            for (int i = 0; i < result.Length; i++)
                response += result[i].ToString("x").PadLeft(2, '0');
            return response;
        }
    }

}
